package handel

import (
	"github.com/gin-gonic/gin"
	"post-pic/model"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	content := c.PostForm("content")
	img := c.PostForm("img")
	if title == "" || content == "" || img == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "参数错误",
		})
		return
	}
	data := model.Contents{
		Title:   title,
		Content: content,
		Img:     img,
	}
	model.DB.Create(&data)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}
func List(c *gin.Context) {
	var contents model.Contents
	model.DB.Find(&contents)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "列表展示成功",
		"data": contents,
	})
}
